<?php

namespace App\Pojo;

class Response
{
    /**
     * 成功响应
     *
     * @param  mixed  $data  响应数据
     * @param  string  $message  响应消息
     * @param  int  $code  响应码
     * @return \Illuminate\Http\JsonResponse
     */
    public static function success($data = null, string $message = '操作成功', int $code = 200)
    {
        return response()->json([
            'code' => $code,
            'message' => $message,
            'data' => $data,
        ]);
    }

    /**
     * 错误响应
     *
     * @param  string  $message  错误消息
     * @param  int  $code  错误码
     * @param  mixed  $data  错误数据
     * @return \Illuminate\Http\JsonResponse
     */
    public static function error(string $message = '操作失败', int $code = 400, $data = null)
    {
        return response()->json([
            'code' => $code,
            'message' => $message,
            'data' => $data,
        ]);
    }

    /**
     * 未找到响应
     *
     * @param  string  $message  错误消息
     * @return \Illuminate\Http\JsonResponse
     */
    public static function notFound(string $message = '资源未找到')
    {
        return self::error($message, 404);
    }

    /**
     * 服务器错误响应
     *
     * @param  string  $message  错误消息
     * @return \Illuminate\Http\JsonResponse
     */
    public static function serverError(string $message = '服务器内部错误')
    {
        return self::error($message, 500);
    }
}
